<%@ page import="edu.auctionmart.Auction"%>
<%@ page import="org.joda.time.DateTime"%>
<!doctype html>
<html>
<head>
<meta name="layout" content="main">
<g:set var="entityName"
	value="${message(code: 'auction.label', default: 'Auction')}" />
<title><g:message code="default.show.label" args="[entityName]" /></title>
</head>
<body>
	<a href="#show-auction" class="skip" tabindex="-1"><g:message
			code="default.link.skip.label" default="Skip to content&hellip;" /></a>
	<div id="show-auction" class="content scaffold-show" role="main">
		<h1>
			${auctionInstance.auctionTitle}
		</h1>
		<g:if test="${flash.message}">
			<div class="message" role="status">
				${flash.message}
			</div>
		</g:if>
		<ol class="property-list auction">

			<g:if test="${auctionInstance?.winner}">
				<li class="fieldcontain"><span id="winner-label"
					class="property-label"><g:message
							code="auction.winner.label" default="Winner" /></span> <span
					class="property-value" aria-labelledby="winner-label">
							${auctionInstance?.winner?.username}
					</span></li>
			</g:if>

			<g:if test="${auctionInstance?.seller}">
				<li class="fieldcontain"><span id="seller-label"
					class="property-label"> <g:message
							code="auction.seller.label" default="Seller" />
				</span> <span class="property-value" aria-labelledby="seller-label">
						${auctionInstance?.seller?.encodeAsHTML()}
				</span></li>
			</g:if>

			<g:if test="${auctionInstance?.item}">
				<li class="fieldcontain"><span id="item-label"
					class="property-label"><g:message code="auction.item.label"
							default="Item" /></span> <span class="property-value"
					aria-labelledby="item-label"><g:link controller="item"
							action="show" id="${auctionInstance?.item?.id}">
							${auctionInstance?.item?.encodeAsHTML()}
						</g:link></span></li>
			</g:if>

			<g:if test="${auctionInstance?.bids}">
				<li class="fieldcontain">
					<span id="bids-label" class="property-label">
						<g:message code="auction.bids.label" default="Number of Bids" />
					</span> 
					<span class="property-value">
						${auctionInstance.bids.size()}
					</span>
				</li>
			</g:if>

			<g:if test="${auctionInstance?.auctionTitle}">
				<li class="fieldcontain"><span id="auctionTitle-label"
					class="property-label"><g:message
							code="auction.auctionTitle.label" default="Auction Title" /></span> <span
					class="property-value" aria-labelledby="auctionTitle-label"><g:fieldValue
							bean="${auctionInstance}" field="auctionTitle" /></span></li>
			</g:if>

			<g:if test="${auctionInstance?.startTime}">
				<li class="fieldcontain"><span id="startTime-label"
					class="property-label"><g:message
							code="auction.startTime.label" default="Start Time" /></span> <span
					class="property-value" aria-labelledby="startTime-label"><g:fieldValue
							bean="${auctionInstance}" field="formattedStartTime" /></span></li>
			</g:if>

			<g:if test="${auctionInstance?.endTime}">
				<li class="fieldcontain"><span id="endTime-label"
					class="property-label"><g:message
							code="auction.endTime.label" default="End Time" /></span> <span
					class="property-value" aria-labelledby="endTime-label"><g:fieldValue
							bean="${auctionInstance}" field="formattedEndTime" /></span></li>
			</g:if>

			<g:if test="${auctionInstance?.currentBid}">
				<li class="fieldcontain"><span id="currentBid-label"
					class="property-label"><g:message
							code="auction.currentBid.label" default="Current Price" /></span> <span
					class="property-value" aria-labelledby="currentBid-label"> ${auctionInstance.currentBid.getAmount() }
				</span></li>
			</g:if>
			<g:else>
				<g:if test="${auctionInstance?.startBid}">
					<li class="fieldcontain"><span id="startBid-label"
						class="property-label"><g:message
								code="auction.startBid.label" default="Current bid" /></span> <span
						class="property-value" aria-labelledby="startBid-label"><g:fieldValue
								bean="${auctionInstance}" field="startBid" /></span></li>
				</g:if>
			</g:else>

			<li class="fieldcontain"><span id="timeLabel"
				class="property-label"> <g:message code="Time remaining" />
			</span> <span class="property-value"> <script language="JavaScript">
						TargetDate = "${auctionInstance.endTime.monthOfYear}/${auctionInstance.endTime.dayOfMonth}/${auctionInstance.endTime.year} ${auctionInstance.endTime.hourOfDay}:${auctionInstance.endTime.minuteOfHour}"	
						CountActive = true;
						CountStepper = -1;
						LeadingZero = true;
						DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
						FinishMessage = "The auction is over!";
					</script> <script language="Javascript"
						src="http://scripts.hashemian.com/js/countdown.js"></script>
			</span></li>
		</ol>

		<g:isLoggedIn>
			<g:if test="${auctionInstance?.endTime >= DateTime.now()}">
				<g:form>
					<fieldset class="buttons">
						<g:hiddenField name="id" value="${auctionInstance?.id}" />

						<g:if test="${auctionInstance?.currentBid}">
							<g:field type="number" id="maxBid" name="maxBid"
								min="${auctionInstance.currentBid.getAmount()}"
								step="0.01"
								value="${fieldValue(bean: auctionInstance.currentBid, field: 'amount')}" />

						</g:if>
						<g:else>
							<g:field type="number" step="0.01" id="maxBid" name="maxBid"
								min="${auctionInstance.startBid}"
								value="${fieldValue(bean: auctionInstance, field: 'startBid')}" />

						</g:else>
						<g:actionSubmit action="bid" value="Place bid"
							onclick="return confirm('Confirm bid');" />
					</fieldset>
				</g:form>
			</g:if>
			
			<g:if test="${auctionInstance?.endTime >= DateTime.now()}">
				<g:form>
					<g:hiddenField name="id" value="${auctionInstance?.id}" />
					<g:hiddenField name="type" value="SMS" />
					<div class="fieldcontain ${hasErrors(bean: reminderInstance, field: 'alertTime', 'error')}">
						<g:actionSubmit action="reminder" value="Create Reminder" onclick="return confirm('Confirm reminder');" />
						<label for="alertTime"> SMS Reminder Time: </label>
						<joda:dateTimePicker name="alertTime" id="alertTime" value="${auctionInstance.endTime.minusMinutes(10)}" />
					</div>
				</g:form>
	
				<g:form>
					<g:hiddenField name="id" value="${auctionInstance?.id}" />
					<g:hiddenField name="type" value="EMAIL" />
					<div class="fieldcontain ${hasErrors(bean: reminderInstance, field: 'alertTime', 'error')}">
						<g:actionSubmit action="reminder" value="Create Reminder" onclick="return confirm('Confirm reminder');" />
						<label for="alertTime"> E-mail Reminder Time: </label>
						<joda:dateTimePicker name="alertTime" id="alertTime" value="${auctionInstance.endTime.minusMinutes(10)}" />
					</div>
				</g:form>
				
								<g:form>
					<g:hiddenField name="id" value="${auctionInstance?.id}" />
					<g:hiddenField name="type" value="IVR" />
					<div
						class="fieldcontain ${hasErrors(bean: reminderInstance, field: 'alertTime', 'error')}">
						<g:actionSubmit action="reminder" value="Create Reminder"
							onclick="return confirm('Confirm reminder');" />
						<label for="alertTime"> Voice call Reminder Time: </label>
						<joda:dateTimePicker name="alertTime" id="alertTime"
							value="${auctionInstance.endTime.minusMinutes(10)}" />
					</div>
				</g:form>
				
			</g:if>
		</g:isLoggedIn>
	</div>
</body>
</html>
